{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 内置函数就是Python给你提供的, 拿来直接用的函数，比如print.，input等。\n",
    "> 版本\\>python3.6 Python [内置函数](https://www.runoob.com/python/python-built-in-functions.html)\n",
    "\n",
    "[<p style=\"color:blue\">截止到python版本3.6.2 python一共提供了68个内置函数，具体如下：</p>](https://mp.weixin.qq.com/s/mRkwft_e4tY_9XVho_Sm5w)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```python\n",
    "abs()           dict()        help()         min()         setattr()\n",
    "all()           dir()         hex()          next()        slice() \n",
    "any()           divmod()      id()           object()      sorted() \n",
    "ascii()         enumerate()   input()        oct()         staticmethod() \n",
    "bin()           eval()        int()          open()        str() \n",
    "bool()          exec()        isinstance()   ord()         sum() \n",
    "bytearray()     ﬁlter()       issubclass()   pow()         super() \n",
    "bytes()         ﬂoat()        iter()         print()       tuple() \n",
    "callable()      format()      len()          property()    type() \n",
    "chr()           frozenset()   list()         range()       vars() \n",
    "classmethod()   getattr()     locals()       repr()        zip() \n",
    "compile()       globals()     map()          reversed()    __import__() \n",
    "complex()       hasattr()     max()          round() \n",
    "delattr()       hash()        memoryview()   set()\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将这68个内置函数综合整理为12大类"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 和数字相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1. 数据类型\n",
    "- bool : 布尔型(True,False)\n",
    "- int : 整型(整数)\n",
    "- float : 浮点型(小数)\n",
    "- complex : 复数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2. 进制转换\n",
    "- bin() 将给的参数转换成二进制\n",
    "- oct() 将给的参数转换成八进制\n",
    "- hex() 将给的参数转换成十六进制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b1010\n",
      "0o12\n",
      "0xa\n"
     ]
    }
   ],
   "source": [
    "print(bin(10))\n",
    "print(oct(10))\n",
    "print(hex(10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3. 数学运算\n",
    "- abs() 返回绝对值\n",
    "- divmode() 返回商和余数\n",
    "- round() 四舍五入\n",
    "- pow(a, b) 求a的b次幂, 如果有三个参数. 则求完次幂后对第三个数取余\n",
    "- sum() 求和\n",
    "- min() 求最小值\n",
    "- max() 求最大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1024.6\n",
      "(6, 2)\n",
      "24\n",
      "2\n",
      "25\n",
      "2\n",
      "12\n"
     ]
    }
   ],
   "source": [
    "print(abs(-1024.6))\n",
    "print(divmod(20,3))\n",
    "print(round(24.478))\n",
    "print(pow(2,7,3))  #2的7次方对3取余\n",
    "print(sum([3,4,5,6,7]))  #求元组各数的和\n",
    "print(min(5,3,9,12,7,2))\n",
    "print(max(5,3,9,12,7,2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 和数据结构相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1. 序列\n",
    "##### （1）列表和元组\n",
    "- list() 将一个可迭代对象转换成列表\n",
    "- tuple() 将一个可迭代对象转换成元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-19T16:09:25.254745Z",
     "start_time": "2020-08-19T16:09:25.247594Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "(1, 2, 3, 4, 5, 6)\n"
     ]
    }
   ],
   "source": [
    "print(list([1,2,3,4,5,6]))\n",
    "print(tuple([1,2,3,4,5,6]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### （2）相关内置函数\n",
    "- reversed() 将一个序列翻转, 返回翻转序列的迭代器\n",
    "- slice() 列表的切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-19T16:09:16.748877Z",
     "start_time": "2020-08-19T16:09:16.741158Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['决', '解', '待', '亟']\n",
      "[3, 4]\n",
      "[2, 4, 6]\n"
     ]
    }
   ],
   "source": [
    "list_str = \"亟待解决\"\n",
    "it = reversed(list_str)   # 不会改变原列表. 返回一个迭代器\n",
    "print(list(it))\n",
    "\n",
    "list_arr = [1,2,3,4,5,6]\n",
    "print(list_arr[2:4])\n",
    "sli = slice(1,6,2)\n",
    "print(list_arr[sli])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### （3）字符串\n",
    "- str() 将数据转化成字符串\n",
    "- format() 与具体数据相关, 用于计算各种小数, 精算等\n",
    "- bytes() 把字符串转化成bytes类型ord() 输入字符找带字符编码的位置\n",
    "- ord() 输入字符找带字符编码的位置\n",
    "- chr() 输入位置数字找出对应的字符\n",
    "- ascii() 是ascii码中的返回该值 不是就返回u\n",
    "- repr() 返回一个对象的string形式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12.3456\n"
     ]
    }
   ],
   "source": [
    "print(str(12.34)+'56')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    hello world!    \n",
      "hello world!        \n",
      "        hello world!\n",
      "11\n",
      "a\n",
      "11\n",
      "13\n",
      "b\n",
      "B\n",
      "11\n",
      "11\n",
      "1.234568e+08\n",
      "1.23e+08\n",
      "1.23E+08\n",
      "1.234568\n",
      "1.23\n",
      "1.2345678900\n",
      "1234.567890\n"
     ]
    }
   ],
   "source": [
    "s = \"hello world!\"\n",
    "print(format(s, \"^20\"))  #居中\n",
    "print(format(s, \"<20\"))  #左对齐\n",
    "print(format(s, \">20\"))  #右对齐\n",
    "\n",
    "print(format(3, 'b' ))    # 二进制:11\n",
    "print(format(97, 'c' ))   # 转换成unicode字符:a\n",
    "print(format(11, 'd' ))   # ⼗进制:11\n",
    "print(format(11, 'o' ))   # 八进制:13 \n",
    "print(format(11, 'x' ))   # 十六进制(⼩写字母):b\n",
    "print(format(11, 'X' ))   # 十六进制(大写字母):B\n",
    "print(format(11, 'n' ))   # 和d⼀样:11\n",
    "print(format(11))         # 和d⼀样:11\n",
    "\n",
    "print(format(123456789, 'e' ))      # 科学计数法. 默认保留6位小数:1.234568e+08\n",
    "print(format(123456789, '0.2e' ))   # 科学计数法. 保留2位小数(小写e):1.23e+08\n",
    "print(format(123456789, '0.2E' ))   # 科学计数法. 保留2位小数(大写E):1.23E+08\n",
    "print(format(1.23456789, 'f' ))     # 小数点计数法. 保留6位小数:1.234568\n",
    "print(format(1.23456789, '0.2f' ))  # 小数点计数法. 保留2位小数:1.23\n",
    "print(format(1.23456789, '0.10f'))  # 小数点计数法. 保留10位小数:1.2345678900\n",
    "print(format(1.23456789e+3, 'F'))   # 小数点计数法. 很大的时候输出INF:1234.567890"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'\\xe4\\xbd\\xa0\\xe4\\xbb\\x8a\\xe5\\xa4\\xa9\\xe5\\x90\\x83\\xe4\\xba\\x86\\xe5\\x90\\x97'\n",
      "97\n",
      "bytearray(b'anlzou')\n",
      "bytearray(b'Anlzou')\n"
     ]
    }
   ],
   "source": [
    "bs = bytes(\"你今天吃了吗\", encoding=\"utf-8\")\n",
    "print(bs)  #返回一个新字节数组. 这个数字的元素是可变的, 并且每个元素的值得范围是[0,256)\n",
    "\n",
    "ret = bytearray(\"anlzou\", encoding='utf-8')\n",
    "print(ret[0])\n",
    "print(ret)\n",
    "ret[0] = 65\n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-19T16:10:30.647545Z",
     "start_time": "2020-08-19T16:10:30.562846Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "97\n",
      "23433\n",
      "A\n",
      "庵\n",
      "ﰘ ﰙ ﰚ ﰛ ﰜ ﰝ ﰞ ﰟ ﰠ ﰡ ﰢ ﰣ ﰤ ﰥ ﰦ ﰧ ﰨ ﰩ ﰪ ﰫ ﰬ ﰭ ﰮ ﰯ ﰰ ﰱ ﰲ ﰳ ﰴ ﰵ ﰶ ﰷ ﰸ ﰹ ﰺ ﰻ ﰼ ﰽ ﰾ ﰿ ﱀ ﱁ ﱂ ﱃ ﱄ ﱅ ﱆ ﱇ ﱈ ﱉ ﱊ ﱋ ﱌ ﱍ ﱎ ﱏ ﱐ ﱑ ﱒ ﱓ ﱔ ﱕ ﱖ ﱗ ﱘ ﱙ ﱚ ﱛ ﱜ ﱝ ﱞ ﱟ ﱠ ﱡ ﱢ ﱣ ﱤ ﱥ ﱦ ﱧ ﱨ ﱩ ﱪ ﱫ ﱬ ﱭ ﱮ ﱯ ﱰ ﱱ ﱲ ﱳ ﱴ ﱵ ﱶ ﱷ ﱸ ﱹ ﱺ ﱻ ﱼ ﱽ ﱾ ﱿ ﲀ ﲁ ﲂ ﲃ ﲄ ﲅ ﲆ ﲇ ﲈ ﲉ ﲊ ﲋ ﲌ ﲍ ﲎ ﲏ ﲐ ﲑ ﲒ ﲓ ﲔ ﲕ ﲖ ﲗ ﲘ ﲙ ﲚ ﲛ ﲜ ﲝ ﲞ ﲟ ﲠ ﲡ ﲢ ﲣ ﲤ ﲥ ﲦ ﲧ ﲨ ﲩ ﲪ ﲫ ﲬ ﲭ ﲮ ﲯ ﲰ ﲱ ﲲ ﲳ ﲴ ﲵ ﲶ ﲷ ﲸ ﲹ ﲺ ﲻ ﲼ ﲽ ﲾ ﲿ ﳀ ﳁ ﳂ ﳃ ﳄ ﳅ ﳆ ﳇ ﳈ ﳉ ﳊ ﳋ ﳌ ﳍ ﳎ ﳏ ﳐ ﳑ ﳒ ﳓ ﳔ ﳕ ﳖ ﳗ ﳘ ﳙ ﳚ ﳛ ﳜ ﳝ ﳞ ﳟ ﳠ ﳡ ﳢ ﳣ ﳤ ﳥ ﳦ ﳧ ﳨ ﳩ ﳪ ﳫ ﳬ ﳭ ﳮ ﳯ ﳰ ﳱ ﳲ ﳳ ﳴ ﳵ ﳶ ﳷ ﳸ ﳹ ﳺ ﳻ ﳼ ﳽ ﳾ ﳿ ﴀ ﴁ ﴂ ﴃ ﴄ ﴅ ﴆ ﴇ ﴈ ﴉ ﴊ ﴋ ﴌ ﴍ ﴎ ﴏ ﴐ ﴑ ﴒ ﴓ ﴔ ﴕ ﴖ ﴗ ﴘ ﴙ ﴚ ﴛ ﴜ ﴝ ﴞ ﴟ ﴠ ﴡ ﴢ ﴣ ﴤ ﴥ ﴦ ﴧ ﴨ ﴩ ﴪ ﴫ ﴬ ﴭ ﴮ ﴯ ﴰ ﴱ ﴲ ﴳ ﴴ ﴵ ﴶ ﴷ ﴸ ﴹ ﴺ ﴻ ﴼ ﴽ ﴾ ﴿ ﵀ ﵁ ﵂ ﵃ ﵄ ﵅ ﵆ ﵇ ﵈ ﵉ ﵊ ﵋ ﵌ ﵍ ﵎ ﵏ ﵐ ﵑ ﵒ ﵓ ﵔ ﵕ ﵖ ﵗ ﵘ ﵙ ﵚ ﵛ ﵜ ﵝ ﵞ ﵟ ﵠ ﵡ ﵢ ﵣ ﵤ ﵥ ﵦ ﵧ ﵨ ﵩ ﵪ ﵫ ﵬ ﵭ ﵮ ﵯ ﵰ ﵱ ﵲ ﵳ ﵴ ﵵ ﵶ ﵷ ﵸ ﵹ ﵺ ﵻ ﵼ ﵽ ﵾ ﵿ ﶀ ﶁ ﶂ ﶃ ﶄ ﶅ ﶆ ﶇ ﶈ ﶉ ﶊ ﶋ ﶌ ﶍ ﶎ ﶏ ﶐ ﶑ ﶒ ﶓ ﶔ ﶕ ﶖ ﶗ ﶘ ﶙ ﶚ ﶛ ﶜ ﶝ ﶞ ﶟ ﶠ ﶡ ﶢ ﶣ ﶤ ﶥ ﶦ ﶧ ﶨ ﶩ ﶪ ﶫ ﶬ ﶭ ﶮ ﶯ ﶰ ﶱ ﶲ ﶳ ﶴ ﶵ ﶶ ﶷ ﶸ ﶹ ﶺ ﶻ ﶼ ﶽ ﶾ ﶿ ﷀ ﷁ ﷂ ﷃ ﷄ ﷅ ﷆ ﷇ ﷈ ﷉ ﷊ ﷋ ﷌ ﷍ ﷎ ﷏ ﷐ ﷑ ﷒ ﷓ ﷔ ﷕ ﷖ ﷗ ﷘ ﷙ ﷚ ﷛ ﷜ ﷝ ﷞ ﷟ ﷠ ﷡ ﷢ ﷣ ﷤ ﷥ ﷦ ﷧ ﷨ ﷩ ﷪ ﷫ ﷬ ﷭ ﷮ ﷯ ﷰ ﷱ ﷲ ﷳ ﷴ ﷵ ﷶ ﷷ ﷸ ﷹ ﷺ ﷻ ﷼ ﷽ ﷾ ﷿ ︀ ︁ ︂ ︃ ︄ ︅ ︆ ︇ ︈ ︉ ︊ ︋ ︌ ︍ ︎ ️ ︐ ︑ ︒ ︓ ︔ ︕ ︖ ︗ ︘ ︙ ︚ ︛ ︜ ︝ ︞ ︟ ︠ ︡ ︢ ︣ ︤ ︥ ︦ ︧ ︨ ︩ ︪ ︫ ︬ ︭ ︮ ︯ ︰ ︱ ︲ ︳ ︴ ︵ ︶ ︷ ︸ ︹ ︺ ︻ ︼ ︽ ︾ ︿ ﹀ ﹁ ﹂ ﹃ ﹄ ﹅ ﹆ ﹇ ﹈ ﹉ ﹊ ﹋ ﹌ ﹍ ﹎ ﹏ ﹐ ﹑ ﹒ ﹓ ﹔ ﹕ ﹖ ﹗ ﹘ ﹙ ﹚ ﹛ ﹜ ﹝ ﹞ ﹟ ﹠ ﹡ ﹢ ﹣ ﹤ ﹥ ﹦ ﹧ ﹨ ﹩ ﹪ ﹫ ﹬ ﹭ ﹮ ﹯ ﹰ ﹱ ﹲ ﹳ ﹴ ﹵ ﹶ ﹷ ﹸ ﹹ ﹺ ﹻ ﹼ ﹽ ﹾ ﹿ ﺀ ﺁ ﺂ ﺃ ﺄ ﺅ ﺆ ﺇ ﺈ ﺉ ﺊ ﺋ ﺌ ﺍ ﺎ ﺏ ﺐ ﺑ ﺒ ﺓ ﺔ ﺕ ﺖ ﺗ ﺘ ﺙ ﺚ ﺛ ﺜ ﺝ ﺞ ﺟ ﺠ ﺡ ﺢ ﺣ ﺤ ﺥ ﺦ ﺧ ﺨ ﺩ ﺪ ﺫ ﺬ ﺭ ﺮ ﺯ ﺰ ﺱ ﺲ ﺳ ﺴ ﺵ ﺶ ﺷ ﺸ ﺹ ﺺ ﺻ ﺼ ﺽ ﺾ ﺿ ﻀ ﻁ ﻂ ﻃ ﻄ ﻅ ﻆ ﻇ ﻈ ﻉ ﻊ ﻋ ﻌ ﻍ ﻎ ﻏ ﻐ ﻑ ﻒ ﻓ ﻔ ﻕ ﻖ ﻗ ﻘ ﻙ ﻚ ﻛ ﻜ ﻝ ﻞ ﻟ ﻠ ﻡ ﻢ ﻣ ﻤ ﻥ ﻦ ﻧ ﻨ ﻩ ﻪ ﻫ ﻬ ﻭ ﻮ ﻯ ﻰ ﻱ ﻲ ﻳ ﻴ ﻵ ﻶ ﻷ ﻸ ﻹ ﻺ ﻻ ﻼ ﻽ ﻾ ﻿ ＀ ！ ＂ ＃ ＄ ％ ＆ ＇ （ ） ＊ ＋ ， － ． ／ ０ １ ２ ３ ４ ５ ６ ７ ８ ９ ： ； ＜ ＝ ＞ ？ ＠ Ａ Ｂ Ｃ Ｄ Ｅ Ｆ Ｇ Ｈ Ｉ Ｊ Ｋ Ｌ Ｍ Ｎ Ｏ Ｐ Ｑ Ｒ Ｓ Ｔ Ｕ Ｖ Ｗ Ｘ Ｙ Ｚ ［ ＼ ］ ＾ ＿ ｀ ａ ｂ ｃ ｄ ｅ ｆ ｇ ｈ ｉ ｊ ｋ ｌ ｍ ｎ ｏ ｐ ｑ ｒ ｓ ｔ ｕ ｖ ｗ ｘ ｙ ｚ ｛ ｜ ｝ ～ ｟ ｠ ｡ ｢ ｣ ､ ･ ｦ ｧ ｨ ｩ ｪ ｫ ｬ ｭ ｮ ｯ ｰ ｱ ｲ ｳ ｴ ｵ ｶ ｷ ｸ ｹ ｺ ｻ ｼ ｽ ｾ ｿ ﾀ ﾁ ﾂ ﾃ ﾄ ﾅ ﾆ ﾇ ﾈ ﾉ ﾊ ﾋ ﾌ ﾍ ﾎ ﾏ ﾐ ﾑ ﾒ ﾓ ﾔ ﾕ ﾖ ﾗ ﾘ ﾙ ﾚ ﾛ ﾜ ﾝ ﾞ ﾟ ﾠ ﾡ ﾢ ﾣ ﾤ ﾥ ﾦ ﾧ ﾨ ﾩ ﾪ ﾫ ﾬ ﾭ ﾮ ﾯ ﾰ ﾱ ﾲ ﾳ ﾴ ﾵ ﾶ ﾷ ﾸ ﾹ ﾺ ﾻ ﾼ ﾽ ﾾ ﾿ ￀ ￁ ￂ ￃ ￄ ￅ ￆ ￇ ￈ ￉ ￊ ￋ ￌ ￍ ￎ ￏ ￐ ￑ ￒ ￓ ￔ ￕ ￖ ￗ ￘ ￙ ￚ ￛ ￜ ￝ ￞ ￟ ￠ ￡ ￢ ￣ ￤ ￥ ￦ ￧ ￨ ￩ ￪ ￫ ￬ ￭ ￮ ￯ ￰ ￱ ￲ ￳ ￴ ￵ ￶ ￷ ￸ ￹ ￺ ￻ ￼ � ￾ ￿ \n",
      "'@'\n",
      "'\\u2620'\n"
     ]
    }
   ],
   "source": [
    "print(ord('a'))\n",
    "print(ord(\"安\"))\n",
    "\n",
    "print(chr(65))\n",
    "print(chr(24245))\n",
    "\n",
    "for i in range(64536, 65536):\n",
    "    print(chr(i), end = \" \")\n",
    "\n",
    "print()\n",
    "print(ascii(\"@\"))\n",
    "print(ascii(\"☠\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "今天\n",
      "吃了3顿\t饭\n",
      "'今天\\n吃了3顿\\t饭'\n"
     ]
    }
   ],
   "source": [
    "s = \"今天\\n吃了%s顿\\t饭\"%3\n",
    "print(s)\n",
    "\n",
    "print(repr(s))   # 原样输出,过滤掉转义字符 \\n \\t \\r 不管百分号%"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2. 数据集合\n",
    "- 字典：dict 创建一个字典\n",
    "- 集合：set 创建一个集合\n",
    "\n",
    "<p style=\"color:red\">frozenset() 创建一个冻结的集合，冻结的集合不能进行添加和删除操作。</p>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.相关内置函数\n",
    "- len() 返回一个对象中的元素的个数\n",
    "- sorted() 对可迭代对象进行排序操作 (lamda)\n",
    "```\n",
    "语法：sorted(Iterable, key=函数(排序规则), reverse=False)\n",
    "        1. Iterable: 可迭代对象\n",
    "        2. key: 排序规则(排序函数), 在sorted内部会将可迭代对象中的每一个元素传递给这个函数的参数. 根据函数运算的结果进行排序\n",
    "        3. reverse: 是否是倒叙. True: 倒叙, False: 正序\n",
    "```\n",
    "   \n",
    "- enumerate() 获取集合的枚举对\n",
    "\n",
    "\n",
    "- all() 可迭代对象中全部是True, 结果才是True\n",
    "- any() 可迭代对象中有一个是True, 结果就是True\n",
    "\n",
    "\n",
    "- zip() 函数用于将可迭代的对象作为参数, 将对象中对应的元素打包成一个元组, 然后返回由这些元组组成的列表. 如果各个迭代器的元素个数不一致, 则返回列表长度与最短的对象相同\n",
    "\n",
    "\n",
    "- fiter() 过滤 (lamda)\n",
    "```\n",
    "语法：fiter(function. Iterable)\n",
    "function: 用来筛选的函数. 在ﬁlter中会自动的把iterable中的元素传递给function. 然后根据function返回的True或者False来判断是否保留此项数据 , Iterable: 可迭代对象\n",
    "```\n",
    "\n",
    "- map() 会根据提供的函数对指定序列做映射(lamda)\n",
    "```\n",
    "语法 : map(function, iterable) \n",
    "可以对可迭代对象中的每一个元素进行映射. 分别去执行 function\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 5, 5, 6, 7, 9, 12, 13, 18]\n",
      "[1, 5, 5, 6, 7, 9, 12, 13, 18]\n",
      "[18, 13, 12, 9, 7, 6, 5, 5, 1]\n"
     ]
    }
   ],
   "source": [
    "lst = [5,7,6,12,1,13,9,18,5]\n",
    "lst.sort()  # sort是list里面的一个方法\n",
    "print(lst)\n",
    "\n",
    "l1 = sorted(lst)  # 内置函数. 返回给你一个新列表  新列表是被排序的\n",
    "print(ll)\n",
    "\n",
    "l2 = sorted(lst, reverse=True)\n",
    "print(l2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 根据字符串长度给列表排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['one', 'two', 'six', 'four', 'five', 'three']\n"
     ]
    }
   ],
   "source": [
    "lst = ['one', 'two', 'three', 'four', 'five', 'six']\n",
    "def fun(s):\n",
    "    return len(s)\n",
    "\n",
    "l1 = sorted(lst, key=fun)\n",
    "print(l1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 : one\n",
      "2 : two\n",
      "3 : three\n",
      "4 : four\n",
      "5 : five\n"
     ]
    }
   ],
   "source": [
    "lst = ['one','two','three','four','five']\n",
    "for index, e1 in enumerate(lst, 1):   # 把索引和元素一起获取,索引默认从0开始. 可以更改\n",
    "    print(index, \":\", e1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(all([1,'hello',True,9]))\n",
    "print(any([0,0,0,False,1,'good']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<zip object at 0x7f3058d76340> <zip object at 0x7f3058d76b00> <zip object at 0x7f3058d76500>\n",
      "<zip object at 0x7f3058d76180>\n",
      "(1, '醉乡民谣', '美国')\n",
      "(2, '驴得水', '中国')\n",
      "(3, '放牛班的春天', '法国')\n",
      "(4, '美丽人生', '意大利')\n",
      "(5, '辩护人', '韩国')\n",
      "(6, '被嫌弃的松子的一生', '日本')\n"
     ]
    }
   ],
   "source": [
    "list1 = [1, 2, 3, 4, 5, 6]\n",
    "list2 = ['醉乡民谣', '驴得水', '放牛班的春天', '美丽人生', '辩护人', '被嫌弃的松子的一生']\n",
    "list3 = ['美国', '中国', '法国', '意大利', '韩国', '日本']\n",
    "\n",
    "print(zip(list1), zip(list2), zip(list3))\n",
    "print(zip(list1, list2, list3))\n",
    "\n",
    "for e1 in zip(list1, list2, list3):\n",
    "    print(e1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<filter object at 0x7f3058936100>\n",
      "[1, 3, 5, 7, 9]\n"
     ]
    }
   ],
   "source": [
    "# 判断奇数\n",
    "def fun(i):\n",
    "    return i % 2 == 1\n",
    "\n",
    "list1 = [1,2,3,4,5,6,7,8,9]\n",
    "l1 = filter(fun, list1) #l1是迭代器\n",
    "print(l1)\n",
    "print(list(l1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 8, 10, 12, 14]\n"
     ]
    }
   ],
   "source": [
    "def fun(i):\n",
    "    return i*2\n",
    "list1 = [1,2,3,4,5,6,7]\n",
    "it = map(fun, list1)\n",
    "print(list(it))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 和作用域相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- locals() 返回当前作用域中的内容\n",
    "- globals() 返回全局作用域中的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a': 10}\n",
      "今天内容很多\n"
     ]
    }
   ],
   "source": [
    "def fun():\n",
    "    a = 10\n",
    "    print(locals())  # 当前作用域中的内容\n",
    "    #print(globals())  # 全局作用域中的内容\n",
    "    print(\"今天内容很多\")\n",
    "    \n",
    "fun()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 和迭代器生成器相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- range() 生成数据\n",
    "- next() 迭代器向下执行一次, 内部实际使⽤用了__ next__()方法返回迭代器的下一个项目\n",
    "- iter() 获取迭代器, 内部实际使用的是__ iter__()⽅方法来获取迭代器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15 12 9 6 3 0 \n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(15, -1, -3):\n",
    "    print(i, end = \" \")\n",
    "\n",
    "print()\n",
    "\n",
    "list1 = [1,2,3,4,5]\n",
    "it = iter(list1)\n",
    "print(it.__next__())\n",
    "print(next(it))\n",
    "print(next(it))\n",
    "print(next(it))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 字符串类型代码的执行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- eval() 执行字符串类型的代码. 并返回最终结果\n",
    "- exec() 执行字符串类型的代码\n",
    "- compile() 将字符串类型的代码编码. 代码对象能够通过exec语句来执行或者eval()进行求值[补充](https://www.runoob.com/python/python-func-compile.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入算数表达式：9%4\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "#s = input(\"请输入算数表达式：\")  #可以动态的执行代码. 代码必须有返回值\n",
    "print(eval(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "2\n",
      "4\n",
      "6\n",
      "8\n",
      "None\n",
      "周杰伦是我**\n"
     ]
    }
   ],
   "source": [
    "s2 = \"for i in range(5):  print(i*2)\"  # exec 执行代码不返回任何内容\n",
    "a = exec(s2)\n",
    "print(a)\n",
    "\n",
    "#动态执行代码\n",
    "exec(\"\"\"\n",
    "def jay(): #不能缩进！\n",
    "    print(\"周杰伦是我**\")\n",
    "\"\"\")\n",
    "jay()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "4\n",
      "47\n",
      "input your name:anlzou\n"
     ]
    }
   ],
   "source": [
    "code1 = \"for i in range(3): print(i**2)\"\n",
    "com = compile(code1, \"\", mode=\"exec\")\n",
    "exec(com)\n",
    "\n",
    "code2 = \"5+6*7\"\n",
    "com2 = compile(code2, \" \", mode=\"eval\")\n",
    "print(eval(com2))\n",
    "\n",
    "code3 = \"name = input('input your name:')\"\n",
    "com3 = compile(code3, \"\", mode=\"single\")\n",
    "exec(com3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 输入输出\n",
    "- print() : 打印输出\n",
    "- input() : 获取用户输出的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello,anlzou and,jack ma."
     ]
    }
   ],
   "source": [
    "print(\"hello\", \"anlzou and\", \"jack ma\", sep=\",\", end=\".\") # sep:打印出的内容用什么连接,end:以什么为结尾"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 内存相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- hash() : 获取到对象的哈希值(int, str, bool, tuple). \n",
    "```\n",
    "hash算法:\n",
    "        (1) 目的是唯一性 \n",
    "        (2) dict 查找效率非常高, hash表.用空间换的时间 比较耗费内存\n",
    "```\n",
    "- id()：获取到对象的内存地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1486713313794157691\n",
      "139845627516208\n",
      "139845629828416\n"
     ]
    }
   ],
   "source": [
    "s = 'anlzou'\n",
    "print(hash(s))\n",
    "\n",
    "list1 = [1,2,3,4,5]  #报错,列表是不可哈希的\n",
    "#print(hash(list1))  \n",
    "\n",
    "print(id(s))  #获取到对象的内存地址\n",
    "print(id(list1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 文件操作相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- open() : 用于打开一个文件, 创建一个文件句柄"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "############\n",
      "##  tets  ## \n",
      "############\n",
      "f = open('file',mode='r',encoding='utf-8')\n",
      "f.read()\n",
      "f.close()\n"
     ]
    }
   ],
   "source": [
    "f = open('file_test.txt',mode='r',encoding='utf-8')\n",
    "text = f.read()\n",
    "print(text)\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 模块相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- __ import__() : 用于动态加载类和函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nimport os\\nname = input(\"输入需要导入的模块名称：\")\\n__import__(name)  # 可以动态导入模块\\n'"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "import os\n",
    "name = input(\"输入需要导入的模块名称：\")\n",
    "__import__(name)  # 可以动态导入模块\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 帮助"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- help() : 函数用于查看函数或模块用途的详细说明"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class str in module builtins:\n",
      "\n",
      "class str(object)\n",
      " |  str(object='') -> str\n",
      " |  str(bytes_or_buffer[, encoding[, errors]]) -> str\n",
      " |  \n",
      " |  Create a new string object from the given object. If encoding or\n",
      " |  errors is specified, then the object must expose a data buffer\n",
      " |  that will be decoded using the given encoding and error handler.\n",
      " |  Otherwise, returns the result of object.__str__() (if defined)\n",
      " |  or repr(object).\n",
      " |  encoding defaults to sys.getdefaultencoding().\n",
      " |  errors defaults to 'strict'.\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __format__(self, format_spec, /)\n",
      " |      Return a formatted version of the string as described by format_spec.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(...)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mod__(self, value, /)\n",
      " |      Return self%value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __rmod__(self, value, /)\n",
      " |      Return value%self.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __sizeof__(self, /)\n",
      " |      Return the size of the string in memory, in bytes.\n",
      " |  \n",
      " |  __str__(self, /)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  capitalize(self, /)\n",
      " |      Return a capitalized version of the string.\n",
      " |      \n",
      " |      More specifically, make the first character have upper case and the rest lower\n",
      " |      case.\n",
      " |  \n",
      " |  casefold(self, /)\n",
      " |      Return a version of the string suitable for caseless comparisons.\n",
      " |  \n",
      " |  center(self, width, fillchar=' ', /)\n",
      " |      Return a centered string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  count(...)\n",
      " |      S.count(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the number of non-overlapping occurrences of substring sub in\n",
      " |      string S[start:end].  Optional arguments start and end are\n",
      " |      interpreted as in slice notation.\n",
      " |  \n",
      " |  encode(self, /, encoding='utf-8', errors='strict')\n",
      " |      Encode the string using the codec registered for encoding.\n",
      " |      \n",
      " |      encoding\n",
      " |        The encoding in which to encode the string.\n",
      " |      errors\n",
      " |        The error handling scheme to use for encoding errors.\n",
      " |        The default is 'strict' meaning that encoding errors raise a\n",
      " |        UnicodeEncodeError.  Other possible values are 'ignore', 'replace' and\n",
      " |        'xmlcharrefreplace' as well as any other name registered with\n",
      " |        codecs.register_error that can handle UnicodeEncodeErrors.\n",
      " |  \n",
      " |  endswith(...)\n",
      " |      S.endswith(suffix[, start[, end]]) -> bool\n",
      " |      \n",
      " |      Return True if S ends with the specified suffix, False otherwise.\n",
      " |      With optional start, test S beginning at that position.\n",
      " |      With optional end, stop comparing S at that position.\n",
      " |      suffix can also be a tuple of strings to try.\n",
      " |  \n",
      " |  expandtabs(self, /, tabsize=8)\n",
      " |      Return a copy where all tab characters are expanded using spaces.\n",
      " |      \n",
      " |      If tabsize is not given, a tab size of 8 characters is assumed.\n",
      " |  \n",
      " |  find(...)\n",
      " |      S.find(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the lowest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Return -1 on failure.\n",
      " |  \n",
      " |  format(...)\n",
      " |      S.format(*args, **kwargs) -> str\n",
      " |      \n",
      " |      Return a formatted version of S, using substitutions from args and kwargs.\n",
      " |      The substitutions are identified by braces ('{' and '}').\n",
      " |  \n",
      " |  format_map(...)\n",
      " |      S.format_map(mapping) -> str\n",
      " |      \n",
      " |      Return a formatted version of S, using substitutions from mapping.\n",
      " |      The substitutions are identified by braces ('{' and '}').\n",
      " |  \n",
      " |  index(...)\n",
      " |      S.index(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the lowest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Raises ValueError when the substring is not found.\n",
      " |  \n",
      " |  isalnum(self, /)\n",
      " |      Return True if the string is an alpha-numeric string, False otherwise.\n",
      " |      \n",
      " |      A string is alpha-numeric if all characters in the string are alpha-numeric and\n",
      " |      there is at least one character in the string.\n",
      " |  \n",
      " |  isalpha(self, /)\n",
      " |      Return True if the string is an alphabetic string, False otherwise.\n",
      " |      \n",
      " |      A string is alphabetic if all characters in the string are alphabetic and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  isascii(self, /)\n",
      " |      Return True if all characters in the string are ASCII, False otherwise.\n",
      " |      \n",
      " |      ASCII characters have code points in the range U+0000-U+007F.\n",
      " |      Empty string is ASCII too.\n",
      " |  \n",
      " |  isdecimal(self, /)\n",
      " |      Return True if the string is a decimal string, False otherwise.\n",
      " |      \n",
      " |      A string is a decimal string if all characters in the string are decimal and\n",
      " |      there is at least one character in the string.\n",
      " |  \n",
      " |  isdigit(self, /)\n",
      " |      Return True if the string is a digit string, False otherwise.\n",
      " |      \n",
      " |      A string is a digit string if all characters in the string are digits and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  isidentifier(self, /)\n",
      " |      Return True if the string is a valid Python identifier, False otherwise.\n",
      " |      \n",
      " |      Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n",
      " |      such as \"def\" or \"class\".\n",
      " |  \n",
      " |  islower(self, /)\n",
      " |      Return True if the string is a lowercase string, False otherwise.\n",
      " |      \n",
      " |      A string is lowercase if all cased characters in the string are lowercase and\n",
      " |      there is at least one cased character in the string.\n",
      " |  \n",
      " |  isnumeric(self, /)\n",
      " |      Return True if the string is a numeric string, False otherwise.\n",
      " |      \n",
      " |      A string is numeric if all characters in the string are numeric and there is at\n",
      " |      least one character in the string.\n",
      " |  \n",
      " |  isprintable(self, /)\n",
      " |      Return True if the string is printable, False otherwise.\n",
      " |      \n",
      " |      A string is printable if all of its characters are considered printable in\n",
      " |      repr() or if it is empty.\n",
      " |  \n",
      " |  isspace(self, /)\n",
      " |      Return True if the string is a whitespace string, False otherwise.\n",
      " |      \n",
      " |      A string is whitespace if all characters in the string are whitespace and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  istitle(self, /)\n",
      " |      Return True if the string is a title-cased string, False otherwise.\n",
      " |      \n",
      " |      In a title-cased string, upper- and title-case characters may only\n",
      " |      follow uncased characters and lowercase characters only cased ones.\n",
      " |  \n",
      " |  isupper(self, /)\n",
      " |      Return True if the string is an uppercase string, False otherwise.\n",
      " |      \n",
      " |      A string is uppercase if all cased characters in the string are uppercase and\n",
      " |      there is at least one cased character in the string.\n",
      " |  \n",
      " |  join(self, iterable, /)\n",
      " |      Concatenate any number of strings.\n",
      " |      \n",
      " |      The string whose method is called is inserted in between each given string.\n",
      " |      The result is returned as a new string.\n",
      " |      \n",
      " |      Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'\n",
      " |  \n",
      " |  ljust(self, width, fillchar=' ', /)\n",
      " |      Return a left-justified string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  lower(self, /)\n",
      " |      Return a copy of the string converted to lowercase.\n",
      " |  \n",
      " |  lstrip(self, chars=None, /)\n",
      " |      Return a copy of the string with leading whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  partition(self, sep, /)\n",
      " |      Partition the string into three parts using the given separator.\n",
      " |      \n",
      " |      This will search for the separator in the string.  If the separator is found,\n",
      " |      returns a 3-tuple containing the part before the separator, the separator\n",
      " |      itself, and the part after it.\n",
      " |      \n",
      " |      If the separator is not found, returns a 3-tuple containing the original string\n",
      " |      and two empty strings.\n",
      " |  \n",
      " |  replace(self, old, new, count=-1, /)\n",
      " |      Return a copy with all occurrences of substring old replaced by new.\n",
      " |      \n",
      " |        count\n",
      " |          Maximum number of occurrences to replace.\n",
      " |          -1 (the default value) means replace all occurrences.\n",
      " |      \n",
      " |      If the optional argument count is given, only the first count occurrences are\n",
      " |      replaced.\n",
      " |  \n",
      " |  rfind(...)\n",
      " |      S.rfind(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the highest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Return -1 on failure.\n",
      " |  \n",
      " |  rindex(...)\n",
      " |      S.rindex(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the highest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Raises ValueError when the substring is not found.\n",
      " |  \n",
      " |  rjust(self, width, fillchar=' ', /)\n",
      " |      Return a right-justified string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  rpartition(self, sep, /)\n",
      " |      Partition the string into three parts using the given separator.\n",
      " |      \n",
      " |      This will search for the separator in the string, starting at the end. If\n",
      " |      the separator is found, returns a 3-tuple containing the part before the\n",
      " |      separator, the separator itself, and the part after it.\n",
      " |      \n",
      " |      If the separator is not found, returns a 3-tuple containing two empty strings\n",
      " |      and the original string.\n",
      " |  \n",
      " |  rsplit(self, /, sep=None, maxsplit=-1)\n",
      " |      Return a list of the words in the string, using sep as the delimiter string.\n",
      " |      \n",
      " |        sep\n",
      " |          The delimiter according which to split the string.\n",
      " |          None (the default value) means split according to any whitespace,\n",
      " |          and discard empty strings from the result.\n",
      " |        maxsplit\n",
      " |          Maximum number of splits to do.\n",
      " |          -1 (the default value) means no limit.\n",
      " |      \n",
      " |      Splits are done starting at the end of the string and working to the front.\n",
      " |  \n",
      " |  rstrip(self, chars=None, /)\n",
      " |      Return a copy of the string with trailing whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  split(self, /, sep=None, maxsplit=-1)\n",
      " |      Return a list of the words in the string, using sep as the delimiter string.\n",
      " |      \n",
      " |      sep\n",
      " |        The delimiter according which to split the string.\n",
      " |        None (the default value) means split according to any whitespace,\n",
      " |        and discard empty strings from the result.\n",
      " |      maxsplit\n",
      " |        Maximum number of splits to do.\n",
      " |        -1 (the default value) means no limit.\n",
      " |  \n",
      " |  splitlines(self, /, keepends=False)\n",
      " |      Return a list of the lines in the string, breaking at line boundaries.\n",
      " |      \n",
      " |      Line breaks are not included in the resulting list unless keepends is given and\n",
      " |      true.\n",
      " |  \n",
      " |  startswith(...)\n",
      " |      S.startswith(prefix[, start[, end]]) -> bool\n",
      " |      \n",
      " |      Return True if S starts with the specified prefix, False otherwise.\n",
      " |      With optional start, test S beginning at that position.\n",
      " |      With optional end, stop comparing S at that position.\n",
      " |      prefix can also be a tuple of strings to try.\n",
      " |  \n",
      " |  strip(self, chars=None, /)\n",
      " |      Return a copy of the string with leading and trailing whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  swapcase(self, /)\n",
      " |      Convert uppercase characters to lowercase and lowercase characters to uppercase.\n",
      " |  \n",
      " |  title(self, /)\n",
      " |      Return a version of the string where each word is titlecased.\n",
      " |      \n",
      " |      More specifically, words start with uppercased characters and all remaining\n",
      " |      cased characters have lower case.\n",
      " |  \n",
      " |  translate(self, table, /)\n",
      " |      Replace each character in the string using the given translation table.\n",
      " |      \n",
      " |        table\n",
      " |          Translation table, which must be a mapping of Unicode ordinals to\n",
      " |          Unicode ordinals, strings, or None.\n",
      " |      \n",
      " |      The table must implement lookup/indexing via __getitem__, for instance a\n",
      " |      dictionary or list.  If this operation raises LookupError, the character is\n",
      " |      left untouched.  Characters mapped to None are deleted.\n",
      " |  \n",
      " |  upper(self, /)\n",
      " |      Return a copy of the string converted to uppercase.\n",
      " |  \n",
      " |  zfill(self, width, /)\n",
      " |      Pad a numeric string with zeros on the left, to fill a field of the given width.\n",
      " |      \n",
      " |      The string is never truncated.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  maketrans(...)\n",
      " |      Return a translation table usable for str.translate().\n",
      " |      \n",
      " |      If there is only one argument, it must be a dictionary mapping Unicode\n",
      " |      ordinals (integers) or characters to Unicode ordinals, strings or None.\n",
      " |      Character keys will be then converted to ordinals.\n",
      " |      If there are two arguments, they must be strings of equal length, and\n",
      " |      in the resulting dictionary, each character in x will be mapped to the\n",
      " |      character at the same position in y. If there is a third argument, it\n",
      " |      must be a string, whose characters will be mapped to None in the result.\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(help(str))  #查看字符串的用途"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 调用相关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- callable() : 用于检查一个对象是否是可调用的. 如果返回True, object有可能调用失败, 但如果返回False. 那调用绝对不会成功"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "print(callable(a)) #False 变量a不能被调用\n",
    "def fun():\n",
    "    print(\"anlzou\")\n",
    "print(callable(fun))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看内置属性"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- dir() : 查看对象的内置属性, 访问的是对象中的__dir__()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']\n"
     ]
    }
   ],
   "source": [
    "print(dir(tuple))  #查看元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "oldHeight": 122.4,
   "position": {
    "height": "255.4px",
    "left": "1176.4px",
    "right": "20px",
    "top": "292px",
    "width": "350px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "varInspector_section_display": "block",
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
